package com.netty.chapter1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Description:
 *
 * @author: StriverFeng
 * @date: 2018-9-21
 * Details:
 */
public class BlockingIOTraining {

    public void serve(int portNumber) throws IOException{
        ServerSocket serverSocket=new ServerSocket(portNumber);
        Socket clientSocket = serverSocket.accept();
         BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        String request,response;
        while ((request =in.readLine()) !=null){
            if ("Done".equals(request)){
                break;
            }
            response=processRequset(request);
            out.println(response);
        }

    }

    private String processRequset(String request) {
        return "Processed";
    }

}
